package com.ruoyi.web.controller.ora;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.ora.domain.AssetsPermission;
import com.ruoyi.ora.service.IAssetsPermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 资产权限Controller
 * 
 * @author liuwp
 * @date 2025-04-10
 */
@RestController
@RequestMapping("/ora/assets_permission")
public class AssetsPermissionController extends BaseController
{
    @Autowired
    private IAssetsPermissionService assetsPermissionService;
    /**
     * 查询资产权限列表
     */
    @PreAuthorize("@ss.hasPermi('ora:assets_permission:list')")
    @GetMapping("/list")
    public TableDataInfo list(AssetsPermission assetsPermission)
    {
        startPage();
        List<AssetsPermission> list = assetsPermissionService.selectAssetsPermissionList(assetsPermission);
        return getDataTable(list);
    }

    /**
     * 导出资产权限列表
     */
    @PreAuthorize("@ss.hasPermi('ora:assets_permission:export')")
    @Log(title = "资产权限", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AssetsPermission assetsPermission)
    {
        List<AssetsPermission> list = assetsPermissionService.selectAssetsPermissionList(assetsPermission);
        ExcelUtil<AssetsPermission> util = new ExcelUtil<AssetsPermission>(AssetsPermission.class);
        util.exportExcel(response, list, "资产权限数据");
    }

    /**
     * 获取资产权限详细信息
     */
    @PreAuthorize("@ss.hasPermi('ora:assets_permission:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(assetsPermissionService.selectAssetsPermissionById(id));
    }

    /**
     * 新增资产权限
     */
    @PreAuthorize("@ss.hasPermi('ora:assets_permission:add')")
    @Log(title = "资产权限", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AssetsPermission assetsPermission)
    {
        return toAjax(assetsPermissionService.insertAssetsPermission(assetsPermission));
    }

    /**
     * 修改资产权限
     */
    @PreAuthorize("@ss.hasPermi('ora:assets_permission:edit')")
    @Log(title = "资产权限", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AssetsPermission assetsPermission)
    {
        return toAjax(assetsPermissionService.updateAssetsPermission(assetsPermission));
    }

    /**
     * 删除资产权限
     */
    @PreAuthorize("@ss.hasPermi('ora:assets_permission:remove')")
    @Log(title = "资产权限", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(assetsPermissionService.deleteAssetsPermissionByIds(ids));
    }


    @PreAuthorize("@ss.hasPermi('ora:assets_permission:add')")
    @Log(title = "资产授权", businessType = BusinessType.INSERT)
    @PostMapping("/grant")
    public AjaxResult grant(AssetsPermission assetsPermission){
        return assetsPermissionService.assetsPermissionGrant(assetsPermission);
    }
}
